// 提交链接：https://leetcode.cn/problems/minimum-time-to-complete-trips/
// lc2187. 完成旅途的最少时间
// 完成日期：2024/10/5
// c++ 二分查找

class Solution {
public:
    long long minimumTime(vector<int>& time, int totalTrips) {
        int mi = *min_element(time.begin(), time.end());
        long long left = 1, right = 1LL * mi * totalTrips;
        while (left < right) 
        {
            long long cnt = 0;
            long long mid = (left + right) / 2;
            for (int v : time) 
                cnt += mid / v;
            
            if (cnt >= totalTrips) 
                right = mid;
            else 
                left = mid + 1;
            
        }
        return left;
    }
};